/**
 * Descriptions：
 * <p>
 * Author：ChenME
 * Date：2017/6/29
 * Email：ibelieve1210@163.com
 */

import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
} from 'react-native';

import MidCommView from './CMEMidCommView';

import homeDay4Array from '../../../LocalData/XMG_Home_D4.json';

import {dealWithIconUrl} from '../utils/CommUtils';

export default class HomeBottomView extends Component {

    static defaultProps = {
        popTopHome: null,
    };


    render() {
        return (
            <View style={styles.pageViewStyle}>
                <View style={styles.topViewStyle}>

                </View>

                <View style={styles.bottomViewStyle}>
                    {this.renderBottomView()}
                </View>
            </View>
        );
    }

    renderBottomView() {
        let itemArray = [];

        let dataArray = homeDay4Array.data;
        for (let i = 0; i < dataArray.length; i++) {
            let data = dataArray[i];
            itemArray.push(
                <MidCommView
                    key={i}
                    title={data.maintitle}
                    subTitle={data.deputytitle}
                    titleColor={data.typeface_color}
                    iconName={dealWithIconUrl(data.imageurl,60)}
                    tplurl={data.tplurl}
                    callbackClickCell={(data)=>this.popToTopView(data)}
                />
            );
        }

        return itemArray;
    }

    // 继续往父级界面传递数据
    popToTopView(data) {
        // 继续执行回调函数
        this.props.popTopHome(data);
    }
}

const styles = StyleSheet.create({
    pageViewStyle: {
        marginTop: 15,
    },

    topViewStyle: {},

    bottomViewStyle: {
        flexWrap: 'wrap',
        flexDirection: 'row',
        justifyContent: 'space-between',
    },
});